import { computed, Ref } from "vue";
import {
  Computed,
  createNamespacedHelpers,
  Mapper,
  MapperForState,
} from "vuex";
import { useStore } from "../store";

const useMapper = (
  mapFun: Mapper<Computed> & MapperForState,
  arry: string[]
) => {
  const store = useStore();
  const MappFns = mapFun(arry);
  const MappState: {
    [k in typeof arry[number]]: any;
  } = {};
  Object.keys(MappFns).forEach((item) => {
    MappState[item as keyof typeof MappState] = computed(
      MappFns[item].bind({ $store: store })
    );
  });

  return MappState;
};

export { useMapper };
